//引入自己封装的jwt工具类
import JWT from '@/utils/jwtutil';
//引入常量
import CONSTS from '@/inits/consts';

/**
 * 问题mark,不可用动态require引入
 */
// import a from "@/img/"+url
// const a = require(`@/img/${aa}${ss}`)
const requImg = () => {
  const LOGINDATA = CONSTS.LOGINDATA;
  let infos = localStorage.getItem('dbtoken')
    ? (infos = JWT.verify(localStorage.getItem('dbtoken'), LOGINDATA.KEY)) //如果没有localStorage的值,解密也是失败
    : '';
  let url = infos?.decode?.sign?.head?.toString();
  let suffix = url?.substr(url.indexOf('.') + 1).toLowerCase();
  url = url?.substr(0, url.indexOf('.'));
  switch (suffix) {
    case 'png':
      return require(`@/img/${url}.png`);
    case 'jpg':
      return require(`@/img/${url}.jpg`);
    case 'gif':
      return require(`@/img/${url}.gif`);
    default:
      return require(`@/img/docuicon.jpg`);
  }
};

export default requImg;
